package com.qfedu.edu.controller;

import com.qfedu.edu.pojo.User;
import com.qfedu.edu.result.R;
import com.qfedu.edu.service.impl.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "用户管理",description = "用户模块")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/findUserAll")
    @ApiOperation("查询所有用户")
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功",response = User.class),
            @ApiResponse(code = 500,message = "查询失败",response = R.class)
    })
    public R findAll(){
        return R.ok().data("userList",userService.findAll());
    }
    @GetMapping("/findUserById/{id}")
    @ApiOperation("根据id查询用户")
    @ApiImplicitParam(name = "id",value = "用户id",required = true,dataType = "int",paramType = "path")
    public R findUserById(@PathVariable("id") Integer id){
        return R.ok().data("user",userService.findUserById(id));
    }
    @PostMapping("addUser")
    @ApiOperation("添加用户")
    public R addUser(@RequestBody User user){
        userService.addUser(user);
        return R.ok();
    }
    @PostMapping("updateUser")
    @ApiOperation("修改用户")
    public R updateUser(@RequestBody User user){
        userService.updateUser(user);
        return R.ok();
    }
    @GetMapping("deleteById")
    @ApiOperation("通过用户ID删除数据")
    public R deleteById(Integer id){
        userService.deleteById(id);
        return R.ok();

    }
}
